﻿using System;
using System.Net;
using SCG.General;

namespace SCG.SolarVengeanceEngine.Orders
{
    //An order with a single Point parameter
    public class PointOrder : StarShipOrder
    {
        //constructor        
        public PointOrder(SVGame game, OrderType ot, int x, int y)
            : base(game, ot)
        {
            X = x;
            Y = y;
        }
        public PointOrder(SVGame game, OrderType ot, SVTokenizer tok)
            : base(game, ot)
        {
            X = tok.TokenInt;
            Y = tok.TokenInt;
        }

        //Destination
        public int X { get; set; }

        public int Y { get; set; }

        //Access destination as Point
        public override SCGPoint TargetPoint
        {
            get
            {
                return new SCGPoint(X, Y);
            }
        }

        //Persistence
        public override string Persist()
        {
            Tokenizer tok = new Tokenizer();
            tok.Tokenize(X, Y);
            return base.Persist() + tok.Result;
        }

        //ToString
        public override string ToString()
        {
            switch (OrderType)
            {
                case OrderType.Move:
                    return "Move to " + X + "," + Y;
                case OrderType.DefendPoint:
                    return "Defend Point " + X + "," + Y;
                default:
                    throw new ArgumentException("Unknown OrderType: " + OrderType);
            }
        }

    }
}
